/**
 * @ClassName KP29_IsMirrorTree
 * @Description: TODO
 * @Author: JCC
 * @CreateTime: 2023/10/26 12:56
 */
public class KP29_IsMirrorTree {
    //测试链接：https://leetcode.com/problems/symmetric-tree/

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            this.val = val;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        return isMrrorTree(root,root);
    }

    public boolean isMrrorTree(TreeNode lRoot, TreeNode rRoot) {
        if (lRoot == null ^ rRoot == null) {
            return false;
        }
        if (lRoot == null && rRoot == null) {
            return true;
        }
        return lRoot.val == rRoot.val && isMrrorTree(lRoot.left,rRoot.right) && isMrrorTree(lRoot.right,rRoot.left);
    }
}
